<?php
// $Id: test_form_guest_submit_link.php 229 2008-03-03 13:27:42Z mikhail.miguel $

// 2007-05-18 K.OHWADA
// XC 2.1

//=========================================================
// WebLinks Module
// 2007-02-20 K.OHWADA
//=========================================================

include_once 'dev_header.php';
include_once 'test_form_class.php';

$test =& weblinks_test_form::getInstance();

dev_header();
echo "<h3>test form: guest submit link</h3>\n";

if ( !$test->has_guest_perm() )
{
	$test->print_error('guest has no permission');
	dev_footer();
}

$link_url  = WEBLINKS_URL.'/submit.php';
$list_url  = WEBLINKS_URL.'/admin/link_list.php?sortid=1';

$ret = $test->logout( false );
if ( !$ret )
{
	dev_footer();
}

//---------------------------------------------------------
// not permit
//---------------------------------------------------------
echo "<h4>scenario 1: not permit</h4>\n";

$test->update_config_by_name( 'use_passwd',  0 );
$test->update_config_by_name( 'use_captcha', 0 );
$test->update_config_by_name( 'cat_path',    0 );
$test->update_config_by_name( 'cat_count',   0 );
$test->update_config_by_name_array( 'auth_submit',      array(1) );
$test->update_config_by_name_array( 'auth_submit_auto', array(1) );

$ret = $test->fetch( $link_url );
if ( !$ret )
{
	dev_footer();
}

if ( $test->match_return_msg( 'not user' ) )
{
	echo "<h4>Test OK !</h4>\n";
}
else
{
	echo "Error: test failed to fetch submit form <br /><hr />\n";
	echo $test->get_body() ."<br /><br />\n";
	dev_footer();
}

//---------------------------------------------------------
// permit
//---------------------------------------------------------
echo "<h4>scenario 2: permit</h4>\n";

$test->update_config_by_name( 'use_passwd', 1 );
$test->update_config_by_name_array( 'auth_submit', array(1, 3) );

$title    = $test->get_randum_title();
$banner   = $test->get_randum_banner( 0 );
$rss_url  = WEBLINKS_URL.'/dev/rss_3.xml';
$rss_flag = 2;	// rss
$passwd   = xoops_makepass();

echo "passwd: $passwd <br />\n";

$ret = $test->user_submit_link( $title, $banner, $rss_flag, $rss_url, $passwd );
if ( !$ret )
{
	dev_footer();
}

if ( $test->match_return_msg( 'submit request link' ) )
{
	echo "<h4>Success !</h4>\n";
	echo "submit link: ".$title." <br /><br />\n";
}
else
{
	echo "Error: submit link form failed: <br /><hr />\n";
	echo $test->get_body() ."<br /><br />\n";
	dev_footer();
}

//---------------------------------------------------------
// permit & approve
//---------------------------------------------------------
echo "<h4>scenario 3: permit and approve: </h4>\n";

$test->update_config_by_name( 'cat_count', 1 );
$test->update_config_by_name_array( 'auth_submit_auto', array(1, 3) );

$title    = $test->get_randum_title();
$banner   = $test->get_randum_banner( 0 );
$rss_url  = WEBLINKS_URL.'/dev/rss_3.xml';
$rss_flag = 2;	// rss
$passwd   = xoops_makepass();

echo "passwd: $passwd <br />\n";

$ret = $test->user_submit_link( $title, $banner, $rss_flag, $rss_url, $passwd );
if ( !$ret )
{
	dev_footer();
}

if ( $test->match_return_msg( 'submit approve link' ) )
{
	echo "<h4>Success !</h4>\n";
	echo "submit link: ".$title." <br /><br />\n";
}
else
{
	echo "Error: submit link form failed: <br /><hr />\n";
	echo $test->get_body() ."<br /><br />\n";
	dev_footer();
}

echo '<a href="'.$list_url.'" target="_blank" >goto link list</a>'."<br />\n";
dev_footer();
// --- end of main ---

?>